package mod.luckymod;

import com.tterrag.registrate.util.entry.RegistryEntry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import java.util.Collection;

import static mod.luckymod.Luckymod.MODID;

public class AllCreativeModeTabs {
    private static final DeferredRegister<CreativeModeTab> REGISTER =
            DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
    public static final RegistryObject<CreativeModeTab> BASE_CREATIVE_TAB = REGISTER.register("base",
            () -> CreativeModeTab.builder()
                    .title(Component.literal("化学制品"))
                    .withTabsBefore(CreativeModeTabs.SPAWN_EGGS)
                    .icon(ModItems.SODIUM_INGOT::asStack)
                    .displayItems(new RegistrateDisplayItemsGenerator())
                    .build());

    private static class RegistrateDisplayItemsGenerator implements CreativeModeTab.DisplayItemsGenerator {
        @Override
        public void accept(CreativeModeTab.ItemDisplayParameters itemDisplayParameters, CreativeModeTab.Output output) {
            // 只获取物品注册项，包括方块物品
            Collection<RegistryEntry<Item>> itemEntries = Luckymod.registrate().getAll(Registries.ITEM);
            for (RegistryEntry<Item> entry : itemEntries) {
                // 直接获取物品实例并添加到标签页
                output.accept(entry.get());
            }
        }
    }
    public static void register(IEventBus modEventBus) {
        REGISTER.register(modEventBus);
    }
}